require 'selenium-webdriver'
driver = Selenium::WebDriver.for :firefox
driver.get "http://translate.google.com/"
wait = Selenium::WebDriver::Wait.new(:timeout => 5)
language_button = wait.until {
element = driver.find_element(:id => "gt-sl-gms")
element if element.displayed?
}
language_button.find_element(:tag_name => "div").click
menu = wait.until {
element = driver.find_element(:id => "gt-sl-gms-menu")
element if element.displayed?
}
langs = menu.find_elements(:class => "goog-menuitem")
norwegian = langs.find { |lang| lang.text == "Norwegian" }
norwegian.find_element(:tag_name => "div").click
puts language_button.text
driver.find_element(:id => "source").send_keys("ost")
result = wait.until {
result = driver.find_element(:id => "result_box").text
result if result.length > 0
}
puts result
driver.quit